package com.example.kemgdemo.util;

import com.example.kemgdemo.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;

/**
 * 学号：1401030048
 * Created by 梁嘉伟 on 2019/7/11
 */
public class ResultUtil {

    private static Result result = new Result();

    private static final Integer num = 10000;

    public static Result success(Object object){

        result.setCode(0);
        result.setMessage("success");
        result.setData(object);
        return result;
    }

    public static Result success(){
        return success(null);
    }

    public static Result error(Integer code, String message){
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result validError(BindingResult bindingResult){
        result.setCode(num-1);
        result.setMessage(bindingResult.getFieldError().getDefaultMessage());
        return result;
    }

    public static Result registerSuccess(){
        result.setCode(num + 1);
        result.setMessage("注册成功");
        result.setData(null);
        return result;
    }

    public static Result loginSuccess(String uuid){
        result.setCode(num + 2);
        result.setMessage("登陆成功");
        result.setData(uuid);
        return result;
    }

    public static Result matchPassword(){
        result.setCode(num + 3);
        result.setMessage("两次密码不一致");
        return result;
    }
}
